//
//  JSON.h
//  OCPopular
//
//  Created by Jarvis on 2024/6/4.
//

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN


/// 判断是空， 如：nil、Nil、NSNull、@""、@"<null>"、@[]、@{}、0Data
FOUNDATION_EXTERN BOOL isEmpty(id object);

/// 非空对象
FOUNDATION_EXTERN BOOL isNotEmpty(id object);

/// 非空字符串
FOUNDATION_EXTERN BOOL isNotEmptyString(id string);

/// 非空数组
FOUNDATION_EXTERN BOOL isNotEmptyArray(id array);

/// 非空字典
FOUNDATION_EXTERN BOOL isNotEmptyDictionary(id dictionary);


/// 字符串读取
/// @param dict 原始数据
/// @param key 目标字段
FOUNDATION_EXTERN NSString *_Nullable stringFromDict(NSDictionary *dict, NSString *key);

/// 字典读取
/// @param dict 原始数据
/// @param key 目标字段
FOUNDATION_EXTERN NSDictionary *_Nullable dictFromDict(NSDictionary *dict, NSString *key);

/// 数组读取
/// @param dict 原始数据
/// @param key 目标字段
FOUNDATION_EXTERN NSArray *_Nullable arrayFromDict(NSDictionary *dict, NSString *key);

/// 自定义数组读取
/// @param dic 原始数据
/// @param key 目标字段
FOUNDATION_EXTERN NSMutableArray *_Nullable arrayFromDictUsingBlock(NSDictionary *dic, NSString *key, id(^usingBlock)(NSDictionary *item));



@interface JSONValue: NSObject

@property (nonatomic, weak, readonly) JSONValue *json;

@property (nonatomic, weak, readonly, nullable) id rawValue;

@property (nonatomic, weak, readonly, nullable) NSString *stringValue;

@property (nonatomic, assign, readonly) NSInteger intValue;
@property (nonatomic, assign, readonly) CGFloat floatValue;

+ (instancetype)jsonWithDictionary:(NSDictionary *)dict;

- (instancetype)objectForKeyedSubscript:(NSString *)aKey;

- (instancetype)objectAtIndexedSubscript:(NSUInteger)index;

@end


NS_ASSUME_NONNULL_END
